package ficheros;

import java.io.*;
import java.util.Random;

public class EscribirFichDataAleatorio {

	public static void main(String[] args) {
		String ficheroAleatorio = "D:\\aleatorio.dat";
		String ficheroTexto = "D:\\aleatorio.txt";

		File fichero = new File(ficheroAleatorio);

		//FileInputStream fileIN = null;
		//DataInputStream dataIN = null;
		FileOutputStream fileOut = null;
		DataOutputStream dataOut = null;
		
		PrintWriter f = null;
		FileReader fr = null;
		BufferedReader br = null;
		
		try {

			
			 f = new PrintWriter(new FileWriter(ficheroTexto));
			fileOut = new FileOutputStream(fichero);
			dataOut = new DataOutputStream(fileOut);

			Random r = new Random();
			double numero;

			for (int i = 0; i < 100; i++) {
				numero = (r.nextInt(19999) - 9999) / 100;
				dataOut.writeDouble(numero);
				f.println(String.valueOf(numero));

			}

			dataOut.close(); // cerramos el stream
			f.close();
		} catch (IOException ioe) {
			System.out.println("Error de E/S");
		}
		/*
		try {

			dataIN = new DataInputStream(new FileInputStream(fichero));

			while (true) {
				System.out.println(dataIN.readDouble());
			}
		} catch (IOException ioe) {
		} finally {
			try {
				dataIN.close();
			} catch (IOException ioe) {
				System.out.println("Error de E/S");
			}

		}*/
		
		try {
			//int i;
			String linea ="";
			fr = new FileReader(ficheroTexto);			
			br =  new BufferedReader(fr);
			try{
			while((linea = br.readLine())!= null){
				System.out.println(linea);
			}
			} catch (IOException ioe){};
			
			try {
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
